package com.andy.qhb.action;

import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import com.andy.qhb.dao.DaoUtils;
import com.andy.qhb.game.GameUser;
import com.andy.qhb.game.Global;
import com.andy.qhb.utils.GmAction;
import com.andy.qhb.utils.SendUtil;
import com.andy.qhb.websocket.MySocketSession;

/**
 * 移除好友
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_112)
public class Action112 implements IWebAction{

	@Override
	public void doAction(MySocketSession myWebSocket, Map<String, Object> data) {
		
		GameUser user = myWebSocket.getUser();
		Long tarId = MapUtils.getLong(data, "userId");
		user.getFriends().remove(tarId);
		DaoUtils.update(user.getFriends());
		MySocketSession session = Global.getSession(tarId);
		if(session != null){
			GameUser tarUsr = session.getUser();
			if(tarUsr != null){
				tarUsr.getFriends().remove(user.getId());
				DaoUtils.update(tarUsr.getFriends());
				SendUtil.send112(user,user.getId());
			}
		}
		
		SendUtil.send112(user,tarId);
		
	}

	
	
	
}
